# Makefile for benchmark program
CXX = g++
CXXFLAGS = -std=c++17 -O2 -Wall -Wextra -pthread
TARGET = benchmark
SOURCES = benchmark.cpp
OBJECTS = $(SOURCES:.cpp=.o)

# Default target
all: $(TARGET)

# Compile the benchmark program
$(TARGET): $(OBJECTS)
	$(CXX) $(OBJECTS) -o $(TARGET) $(CXXFLAGS)

# Compile object files
%.o: %.cpp
	$(CXX) $(CXXFLAGS) -c $< -o $@

# Clean build files
clean:
	rm -f $(OBJECTS) $(TARGET)

# Install (copy to system path)
install: $(TARGET)
	sudo cp $(TARGET) /usr/local/bin/

# Uninstall
uninstall:
	sudo rm -f /usr/local/bin/$(TARGET)

# Run tests
test: $(TARGET)
	@echo "Running quick benchmark test..."
	./$(TARGET) --cpu 2 --vm 2 --time 5 --verbose

# Performance test
perf-test: $(TARGET)
	@echo "Running performance benchmark..."
	./$(TARGET) --cpu 4 --vm 4 --time 30 --pin

# Help
help:
	@echo "Available targets:"
	@echo "  all        - Build the benchmark program"
	@echo "  clean      - Remove build files"
	@echo "  install    - Install to /usr/local/bin"
	@echo "  uninstall  - Remove from /usr/local/bin"
	@echo "  test       - Run quick test (2 CPU + 2 VM threads, 5 seconds)"
	@echo "  perf-test  - Run performance test (4 CPU + 4 VM threads, 30 seconds)"
	@echo "  help       - Show this help message"

.PHONY: all clean install uninstall test perf-test help 